<template>
<view class="page">
    <view @tap="previewImage" class="fui-picture">
        <image :src="Image"></image>
    </view>
    <view @tap="savePicture" class="save-btn">保存图片</view>
    <view class="explain-navbar">
        <i class="icox icox-zhuyi"></i>
        <view class="expl">保存至相册</view>
    </view>
    <!-- <view :class="'fui-toast ' + (FoxUIToast.show?'in':'out')">
        <view class="text">{{FoxUIToast.text}}</view>
    </view> -->
</view>
</template>

<script>
var t = getApp().globalData,
    e = (t.requirejs("core"), t.requirejs("foxui"));

export default {
  data() {
    return {
      accredit: "",
      errMsg: "",
      Image: "https://api.clubmall.cn/attachment/images/7/2017/11/r13oT11buG60bn2ntVp1q4pe3B6EGQ.jpeg"
    };
  },

  components: {},
  props: {},
  onLoad: function (t) {},
  methods: {
    previewImage: function () {
      wx.previewImage({
        current: "https://api.clubmall.cn/attachment/images/7/2017/11/r13oT11buG60bn2ntVp1q4pe3B6EGQ.jpeg",
        urls: ["https://api.clubmall.cn/attachment/images/7/2017/11/r13oT11buG60bn2ntVp1q4pe3B6EGQ.jpeg"]
      });
    },
    savePicture: function () {
      var a = this;
      wx.getSetting({
        success: function (i) {
          i.authSetting["scope.writePhotosAlbum"] ? (wx.showLoading({
            title: "图片下载中..."
          }), setTimeout(function () {
            wx.hideLoading();
          }, 1e3), wx.downloadFile({
            url: "https://api.clubmall.cn/attachment/images/7/2017/11/r13oT11buG60bn2ntVp1q4pe3B6EGQ.jpeg",
            success: function (t) {
              wx.saveImageToPhotosAlbum({
                filePath: t.tempFilePath,
                success: function (t) {
                  e.toast(a, "保存图片成功");
                },
                fail: function (t) {
                  a.setData({
                    errMsg: t.errMsg
                  }), e.toast(a, "保存图片失败");
                }
              });
            }
          })) : wx.authorize({
            scope: "scope.writePhotosAlbum",
            fail: function () {
              t.getmsg("writePhotosAlbum", "使用保存图片功能");
            }
          });
        }
      });
    }
  }
};
</script>
<style>
@import "./poster.css";
</style>